package com.hh.demo.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hh.demo.entity.Bookinfo;
import com.hh.demo.mapper.BookinfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 吉吉国王
 * @since 2022-07-11
 */
@Service
public class BookinfoService{
    @Resource
    private BookinfoMapper bookinfoMapper;
    //录入图书
    public void insertBookInfo(String bookNo,String bookName,String author,String bookCard,Integer bookNum){
        bookinfoMapper.insertBookInfo(bookNo,bookName,author,bookCard,bookNum);
    }
    //根据卡号查询图书信息
    public Bookinfo queryBookInfo(String bookCard){
//        QueryWrapper<Bookinfo> wrapper = new QueryWrapper<>();
//        wrapper.eq("bookCard",bookCard);
//        return bookinfoMapper.selectOne(wrapper);
        return bookinfoMapper.queryBookInfo(bookCard);
    }
    //查询卡号是否在数据库中存在
    public boolean isExistBook(String card){
        QueryWrapper<Bookinfo> wrapper = new QueryWrapper<>();
        wrapper.eq("bookCard",card);
        return bookinfoMapper.exists(wrapper);
    }
}
